package com.github.binarylei.hadoop.flowsum;

import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class FlowSumMapper extends Mapper<LongWritable, Text, Text, FlowBean>{

	//mapreduce框架每读一行数据就调用一次该方法
	@Override
	protected void map(LongWritable key, Text value, Context context)
			throws IOException, InterruptedException {
		String line = value.toString();
        String[] fields = StringUtils.split(line, "\t");

        String phoneNB = fields[0];
        long up_flow = Long.parseLong(fields[1]);
        long d_flow = Long.parseLong(fields[2]);

        context.write(new Text(phoneNB), new FlowBean(phoneNB, up_flow, d_flow));
    }
}
